#ifndef IEEE_ROBOT_H_
#define IEEE_ROBOT_H_

#define CONTROLLER 0
#define TIMERS 1

/*-------------compilation flags---------------------------------*/
#define WISKER_DEBOUNCE 1     /* 1 if we want to debounce wisker switches */
#define QUALIFICATION   0     /* 1 to set up qualification code */

#define ENABLE_WDT  1    /* 1 enables WDT and Power Up delay startup sequencye */
#define DEBUG       0    /* 1 enables debug statements */
 
#define CHARGE_UP   0    /* 1 enables charge up cycle (loop until VCC == VCC_THRESH */
#define DROP_ARRAY  1    /* 1 enables drop array sequence */

//1 uses Timers to control servo, 0 servo controller
#define SERVO TIMERS     /* TIMERS sets servo method to timers */

//define if servo is in back or front of robot
//1 = servo in Back
//0 = servo in front
#define SERVO_BACK 0

//reset power flags
#define POR_BIT 1
#define WDT_BIT 3

//generic macros

//global settings
#define FOSC   4000000    //Fosc = 4 MHz
//#define FOSC 20000000
#define TCY (4/FOSC)
#define TCYCNT_4_MS (0.001*(FOSC/4))

//A2D Threshold values
#define VCC              4
#define VCC_THRESH  	((unsigned short int) ((VCC/0.00488)+0.5))   //Threshold = VCC_THRESH/.00488
//#define VCC_THRESH       0x334
#define PHOTO_THRESH  	0x0200  	//set photo thresh to 2.5 volts
                                   //this means photo resistance is 
                                   //equal to pull up resistor
//timer 3 macros
#define MILLI_SECOND     64535
#define tmr3_reset()     TMR3H = (MILLI_SECOND) >> 8; \
                         TMR3L = (MILLI_SECOND) & 0xFF

//interrupt macros
#define enable_int_global()  (INTCON = INTCON | 0x80)
#define disable_int_global() (INTCON = INTCON & 0x7F)

#define enable_int_low()     (INTCON = INTCON | 0x40)
#define disable_int_low()    (INTCON = INTCON & 0xBF)

#define enable_int_all()     (INTCON = INTCON | 0xC0)
#define disable_int_all()    (INTCON = INTCON & 0x3F)
 
//servo macros
#define disable_wisker_interrupts()     INTCONbits.RBIE = 0
#define enable_wisker_interrupts()      INTCONbits.RBIE = 1
#define disable_servo_interrupts()      

//delay functions
#define delay() for (i = 0;i < 1000;++i) _asm nop _endasm
//bit manipulation routines
#define set_bit(REG,BIT) ((REG) | (1 << (BIT)))
#define clear_bit(REG,BIT) ((REG) & (~(1 <<(BIT))))
#define test_bit(REG,BIT) ((REG) & (1 << (BIT)))

#endif
